package com.obtk.property.config;

import com.obtk.property.pojo.Manager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器
 */
public class LoginInterceptor implements HandlerInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
        Manager user = (Manager) request.getSession().getAttribute("sysUser");
        if (null == user) {
            response.sendRedirect("/login");
            logger.info("前置拦截器-登录失败....{} 当前登录用户{}", flag, user);
            flag = false;
        } else {
            flag = true;
        }
        return flag;
    }


}
